package cn.edu.zafu.bigdata.zengyadian;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class NewsContent {
    public static void createTable() throws SQLException {
        try {
            DBConnection connection = (DBConnection) DBConnection.getConnection();
            String sql = "CREATE TABLE IF NOT EXISTS news_content (" +
                    "id INT AUTO_INCREMENT PRIMARY KEY," +
                    "category_id INT NOT NULL," +
                    "title VARCHAR(255) NOT NULL," +
                    "content TEXT NOT NULL," +
                    "FOREIGN KEY (category_id) REFERENCES news_category(id)" +
                    ")";
            PreparedStatement statement = ((Connection) connection).prepareStatement(sql);
            statement.executeUpdate();
            statement.close();
            ((Connection) connection).close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
